package mapEditor.vo
{
	import flash.events.EventDispatcher;
	
	import mapEditor.view.MapAssetBase;
	
	public class MapVO extends EventDispatcher
	{
		private var _mapName:String;
		private var _mapDescription:String;
		private var _mapRow:int=0;
		private var _mapCols:int=0;
		private var _cellSize:Number;
		private var _mapGridList:Array=[];
		private var _roadArray:Array=[];
		private var _assetLibPath:Array=[];
		private var _assetArray:Vector.<MapAssetBase>=new Vector.<MapAssetBase>();
		private var _mapType:int=0;//地图类型:0=Diamond;1=Staggered
		
		public function MapVO()
		{
		}
		
		public function get mapName():String
		{
			return _mapName;
		}
		
		public function set mapName(value:String):void
		{
			_mapName = value;
		}
		
		public function get mapDescription():String
		{
			return _mapDescription;
		}
		
		public function set mapDescription(value:String):void
		{
			_mapDescription = value;
		}
		
		/**
		 *地图上所有物件列表
		 */		
		public function get assetArray():Vector.<MapAssetBase>
		{
			return _assetArray;
		}
		
		/**
		 *地图上所有物件列表
		 */	
		public function set assetArray(value:Vector.<MapAssetBase>):void
		{
			_assetArray = value;
		}
		
		/**
		 *地图格子对象列表
		 */		
		public function get mapGridList():Array
		{
			return _mapGridList;
		}
		
		/**
		 *地图格子对象列表
		 */
		public function set mapGridList(value:Array):void
		{
			_mapGridList = value;
		}
		
		public function get mapRow():int
		{
			return _mapRow;
		}
		
		public function set mapRow(value:int):void
		{
			clearMapGridList();
			_mapRow = value;
			if(value>0 && _mapCols>0) setMapGridList();
		}
		
		public function get mapCols():int
		{
			return _mapCols;
		}
		
		public function set mapCols(value:int):void
		{
			clearMapGridList();
			_mapCols = value;
			if(_mapRow>0 && value>0) setMapGridList();
		}
		
		public function get cellSize():Number
		{
			return _cellSize;
		}
		
		public function set cellSize(value:Number):void
		{
			_cellSize = value;
		}
		
		public function get roadArray():Array
		{
			for(var i:int=0;i<_mapGridList.length;i++)
			{
				_roadArray[i]=[];
				for(var c:int=0;c<_mapGridList[i].length;c++)
				{
					_roadArray[i][c]=_mapGridList[i][c].roadType;
				}
			}
			
			return _roadArray;
		}
		
		/**
		 *设置地图格子数组 
		 */		
		private function setMapGridList():void
		{
			if(_mapType==0)
			{
				for(var i:int=0;i<_mapRow;i++)
				{
					_mapGridList[i]=[];
					for(var c:int=0;c<mapCols;c++)
					{
						_mapGridList[i][c]=new MapGridVO();
						_mapGridList[i][c].roadType=0;
					}
				}
			}
			else
			{
				for(i=0;i<=_mapCols*2;i++)
				{
					_mapGridList[i]=[];
					for(c=0;c<=_mapRow;c++)
					{
						_mapGridList[i][c]=new MapGridVO();
						_mapGridList[i][c].roadType=0;
					}
				}
			}
		}
		
		/**
		 *清理地图格子数组 
		 */	
		private function clearMapGridList():void
		{
			for(var i:int=0;i<mapGridList.length;i++)
			{
				for(var c:int=0;c<mapGridList[i].length;c++)
				{
					var mapGridVO:MapGridVO=_mapGridList[i][c] as MapGridVO;
					mapGridVO.dispose();
					mapGridVO=null;
				}
				mapGridList[i]=null;
			}
			mapGridList=[];
		}
		
		/**
		 *地图资源库Xml配置路径
		 */		
		public function get assetLibPath():Array
		{
			return _assetLibPath;
		}
		
		/**
		 *地图资源库Xml配置路径
		 */
		public function set assetLibPath(value:Array):void
		{
			_assetLibPath = value;
		}
		
		/**
		 *地图类型:0=Diamond;1=Staggered 
		 */		
		public function get mapType():int
		{
			return _mapType;
		}
		
		/**
		 *地图类型:0=Diamond;1=Staggered 
		 */		
		public function set mapType(value:int):void
		{
			_mapType = value;
		}
		
	}
}